/*
 * @Title: 姿美汇H5商城首页分类
 * @Author: JSL
 * @Date:   2018-10-12
 * @Last Modified by:   JSL
 * @Last Modified time: 2018-10-12
 */
var dataInfo = {},
	template = {
		init: function() {
			Vue.use(VueLazyload, {
				preLoad: 1.3,
				error: 'https://h5.meetao.com/img/product/init.png',
				loading: 'https://h5.meetao.com/img/product/init.png',
				attempt: 1
			})
			dataInfo.init = new Vue({
				el: '#app',
				data: {
					all: false,
					code: getQueryString('code'),
					name: getQueryString('name'),
					isFx: 1,
					isDz: 0,
					page: 1,
					limit: 10,
					loading: false,
					finished: false,
					isLoading: false,
					listData: [], //商品集合
				},
				methods: {
					onLoad: function() { //懒加载
						template.getProductList();
					},
					onRefresh: function() { //下拉刷新
						dataInfo.init.all = false;
						this.listData = [];
						this.page = 1;
						setTimeout(function(){
							template.getProductList();
						},500);
					},
					toProduct: function(data) { //toProduct
						jumpProductDetails(data);
					},
				},
				computed:{
					height:function(){
						return document.body.clientHeight + 'px';
					}
				}
			});
			template.getProductList();
			$(document).attr("title", unescape(dataInfo.init.name));
		},
		getProductList: function() { // template.getProductList();
			ajaxTemplate(addressUrl + SERVICE.queryFxGoodsList, function(data) {
				console.log(data);
				var daTa = data.data.result;
				if(data.tag == 0) {
					dataInfo.init.listData = JSON.parse(JSON.stringify(dataInfo.init.listData.concat(daTa)));
					if(daTa.length < dataInfo.init.limit) {
						console.log("无数据")
						dataInfo.init.finished = true;
						dataInfo.init.listData.length > 4 ? dataInfo.init.all = true : '';
					} else {
						console.log('有数据')
						dataInfo.init.finished = false;
					};
					dataInfo.init.loading = false;
					dataInfo.init.isLoading = false;
					//					是否要有秒杀
					//					daTa.forEach(function(item, index) {
					//						if(item.isKill !== 0) {
					//							dataInfo.init.listData.push(item);
					//						};
					//					});
					//					setTimeout(function() {
					//						var tid = "index" + (daTa.length - 1);
					//						$('#' + tid).ready(function() {
					//							$(".loadImgBox").addClass("rgba").hide();
					//						});
					//					}, 300);
				} else {
					dataInfo.init.$toast(data.errMsg);
				};
			}, {
				limit: dataInfo.init.limit,
				page: dataInfo.init.page++,
				code: dataInfo.init.code
			});
		},
	};
template.init();